package com.scsj.supermarket.presenter;

import android.content.Context;
import android.util.Log;

import com.orhanobut.logger.Logger;
import com.scsj.supermarket.base.LoginBase;
import com.scsj.supermarket.base.SMSBase;
import com.scsj.supermarket.bean.BaseBean;
import com.scsj.supermarket.bean.LoginBean;
import com.scsj.supermarket.config.RxSPConfig;
import com.scsj.supermarket.model.LoginModel;
import com.scsj.supermarket.model.SMSModel;
import com.vondear.rxtools.RxSPTool;

import dkmvp.mvp.BasePresenter;
import dkmvp.net.ResponseCallback;
import okhttp3.RequestBody;

/**
 * 基础presenter 实现示例
 */

public class SMSPresenter extends BasePresenter implements SMSBase.IPresenter {

    private SMSBase.IModel mModel;
    private SMSBase.IView mView;

    public SMSPresenter(SMSBase.IView view) {
        mView = view;
        mModel = new SMSModel();
    }

    @Override
    public void deliverData(RequestBody requestBody) {

        addSubscription(mModel.getData(requestBody, new ResponseCallback<BaseBean>() {
            @Override
            public void onSuccess(BaseBean result) {

                if (result.getStatusCode() == 200 ) {

                    mView.showSMSSuccessMsg("获取成功" , result);
                    Logger.d("短信验证码发送成功" + result.toString());

                } else {
                    mView.showSMSErrorMsg(result.getMsg());
                }

            }

            @Override
            public void onFaild(String msg) {
                mView.showSMSErrorMsg("网络连接失败");
                Log.e("onFaild", msg + "");
            }
        }));
    }
}
